﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ENLibraryClass;

namespace uacars
{
    public partial class frmLogin : Form
    {

        public frmLogin()
        {
            InitializeComponent();
        }

        private void btnInicio_Click(object sender, EventArgs e)
        {
            bool logueado = false;
            Label error = new Label();


            //COMPROBAMOS LOS DATOS
            ENEmpleados empleados = new ENEmpleados(0, "", "", "", "", "", "", "", "", "", "", "", "", DateTime.Parse("01/01/1900"), tbxLogin.Text, tbxPassword.Text);
            DataTable datos = empleados.BuscarEmpleadosPor();

            //************************************************************************
            if (datos.Rows.Count > 0)
            {
                logueado = true;
            }

            //SI LOS DATOS SON CORRECTOS, INICIAMOS SESION
            if (logueado == true)
            {
                //frmBarraMenu barra = new frmBarraMenu();
                //barra.MdiParent = this.MdiParent;
                //barra.Show();

                frmMenuSuperior menu = new frmMenuSuperior(tbxLogin.Text,tbxPassword.Text);
                menu.MdiParent = this.MdiParent;

                //FALTA PONER EL VALOR DEL NOMBRE QUE TENGA EN LA BASE DE DATOS
                //menu.labelUsuario.Text = tbxLogin.Text;
                //**************************************************************
                menu.labelUsuario.Text = datos.Rows[0].ItemArray[2].ToString() +" "+ datos.Rows[0].ItemArray[3].ToString() +" "+ datos.Rows[0].ItemArray[4].ToString();
                menu.labelOcupacion.Text = datos.Rows[0].ItemArray[11].ToString();

                menu.Show();

                frmFondo fondo = new frmFondo();
                fondo.MdiParent = this.MdiParent;
                fondo.Show();

                this.Close();
            }
            else
            {
                MessageBox.Show("Login o contraseña incorrectos.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                tbxPassword.Text = "";
            }
        }

        private void tbxPassword_Click(object sender, EventArgs e)
        {
            tbxPassword.Text = "";
            tbxPassword.UseSystemPasswordChar = true;
        }

        private void tbxLogin_Click(object sender, EventArgs e)
        {
            tbxLogin.Text = "";
        }

        private void tbxPassword_TextChanged(object sender, EventArgs e)
        {
            tbxPassword.UseSystemPasswordChar = true;
        }
    }
}
